package com.itbac.config.sentinel;

import com.alibaba.csp.sentinel.adapter.servlet.callback.RequestOriginParser;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * sentinel 授权规则
 * 黑白名单
 */
//@Component
public class RequestOriginParserDefiniion implements RequestOriginParser {
    // 定义区分来源：本质作用是通过request域获取到来源标识
    // app  pc
    //然后交给  流控应用 位置进行黑白名单的 匹配
    @Override
    public String parseOrigin(HttpServletRequest httpServletRequest) {
        //标识请求的来源
        String source = httpServletRequest.getParameter("source");
        if (StringUtils.isEmpty(source)){
            throw new RuntimeException("sentinel black and white source");
        }
        return source;
    }
}
